/*
 * The MIT License (MIT)
 *
 * Copyright © 2020 xrv <xrg@live.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package io.github.ehlxr.utils;

import org.bouncycastle.crypto.CipherParameters;
import org.bouncycastle.crypto.engines.AESFastEngine;
import org.bouncycastle.crypto.modes.CBCBlockCipher;
import org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher;
import org.bouncycastle.crypto.params.KeyParameter;
import org.bouncycastle.crypto.params.ParametersWithIV;
import org.bouncycastle.util.encoders.Hex;
/**
 * AES encryption and decryption tool.
 */
public class AESTool {
	private static final byte[] initVector = {0x32, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31,
			0x38, 0x27, 0x36, 0x35, 0x33, 0x23, 0x32, 0x31};

	/**
	 * Encrypt the content with a given key using aes algorithm.
	 *
	 * @param content
	 * @param key     must contain exactly 32 characters
	 * @return
	 * @throws Exception
	 */
	public static String encrypt(String content, String key) throws Exception {
		if (key == null) {
			throw new IllegalArgumentException("Key cannot be null!");
		}
		String encrypted = null;
		byte[] keyBytes = key.getBytes();
		if (keyBytes.length != 32 && keyBytes.length != 24
				&& keyBytes.length != 16) {
			throw new IllegalArgumentException(
					"Key length must be 128/192/256 bits!");
		}
		byte[] encryptedBytes = null;
		encryptedBytes = encrypt(content.getBytes(), keyBytes, initVector);
		encrypted = new String(Hex.encode(encryptedBytes));
		return encrypted;
	}

	/**
	 * Decrypt the content with a given key using aes algorithm.
	 *
	 * @param content
	 * @param key
	 * 			must contain exactly 32 characters
	 * @return
	 * @throws Exception
	 */
	public static String decrypt(String content, String key) throws Exception {
		if (key == null) {
			throw new IllegalArgumentException("Key cannot be null!");
		}
		String decrypted = null;
		byte[] encryptedContent = Hex.decode(content);
		byte[] keyBytes = key.getBytes();
		byte[] decryptedBytes = null;
		if (keyBytes.length != 32 && keyBytes.length != 24
				&& keyBytes.length != 16) {
			throw new IllegalArgumentException(
					"Key length must be 128/192/256 bits!");
		}
		decryptedBytes = decrypt(encryptedContent, keyBytes, initVector);
		decrypted = new String(decryptedBytes);
		return decrypted;
	}

	/**
	 * Encrypt data.
	 *
	 * @param plain
	 * @param key
	 * @param iv
	 * @return
	 * @throws Exception
	 */
	public static byte[] encrypt(byte[] plain, byte[] key, byte[] iv) throws Exception {
		PaddedBufferedBlockCipher aes = new PaddedBufferedBlockCipher(
				new CBCBlockCipher(new AESFastEngine()));
		CipherParameters ivAndKey = new ParametersWithIV(new KeyParameter(key),
				iv);
		aes.init(true, ivAndKey);
		return cipherData(aes, plain);
	}

	/**
	 * Decrypt data.
	 *
	 * @param cipher
	 * @param key
	 * @param iv
	 * @return
	 * @throws Exception
	 */
	public static byte[] decrypt(byte[] cipher, byte[] key, byte[] iv)
			throws Exception {
		PaddedBufferedBlockCipher aes = new PaddedBufferedBlockCipher(
				new CBCBlockCipher(new AESFastEngine()));
		CipherParameters ivAndKey = new ParametersWithIV(new KeyParameter(key),
				iv);
		aes.init(false, ivAndKey);
		return cipherData(aes, cipher);
	}

	/**
	 * Encrypt or decrypt data.
	 *
	 * @param cipher
	 * @param data
	 * @return
	 * @throws Exception
	 */
	private static byte[] cipherData(PaddedBufferedBlockCipher cipher, byte[] data)
			throws Exception {
		int minSize = cipher.getOutputSize(data.length);
		byte[] outBuf = new byte[minSize];
		int length1 = cipher.processBytes(data, 0, data.length, outBuf, 0);
		int length2 = cipher.doFinal(outBuf, length1);
		int actualLength = length1 + length2;
		byte[] result = new byte[actualLength];
		System.arraycopy(outBuf, 0, result, 0, result.length);
		return result;
	}

	public   static void main(String[] args) throws Exception {
		String appid = "canairport001";
		String key = "1111111111111111";
		String xml = "<root><name>test</name><name>test</name><name>test</name><name>test</name><name>test</name><name>test</name><name>test</name><name>test</name><name>test</name><name>test</name><name>test</name><name>test</name><name>test</name><name>test</name><name>test</name><name>test</name><name>test</name></root>";
		String str ="fbac6c10aa8e0f946e02e0b57b35c7483b57b485c41147c31511ad1c212e3388ed223a2ddadd8d98c2306841b58927d8d8da4013d4057a20d00d87fb6c8ad3a66495638b6ddb42e405acdd4e28d0de2928f5f03b3b049070d4d1302f9cd9886c3b0052e1e61edb0f4de74c0f592a22d10bceb06944688c5a0521adb37b74648a2647357229058094deae4950053f6d67db76c4d013c024a1128b471f8d5a0f4765a447fd92eb6c84f5db6c5b2aa0721ce027d311cdb95e285f6e6f1deb6027e9a666ab5600fe3d094f7008a08b415c876d8fa48f5cd0e1b66e2a81fb8763c242620f4109607e17a9ef8e61fedf630f3900b34b39efd19674d1a9968b8ed5ecb7f344becbf2d9928ab6e52cca89dd261538335a3e14b11c216dff10ac1567d5a52a26c600265557d20b8bfff97007526371b381652dc12dd92034f8d62d4a760497dc3c7168d03932e33e455661157b36a13c6ac3cffb32a2a21816333e410dea8a147346de7a83b26d823056be8e9ec18406bb7e5e95f164e0e69c6ed398d3163133d6aa912d239897720db3392766ee5780da46b8ecb626aeb22ce4ab2cd1e397ca8f9063796301403d1b9a26cdaae1a90789d1d036c74da0566a4a9428dcb4af17d743cbda2de768d90001f485145254da6a60fb4ada8419ba906bd38c991649f8422d98fc9ec8d55503753e274e8a16ec9a6f06f04bd4ea99c9e4c9b5389bb077c8a63959fbc2574456e614bb3b64d4469c8d8d773fd774f366c4f50dbc5f985afc2511f74001dbb1947d88134faf58fb4f9cb43047e4aa5e821147d6aa1b868cc46fbae459e5a784269739b157ea59e3c7bff6b28b6f0f9895c1ddc23467d221a55ac9ca3cb6b773a94b7dcc86e73bf3e467609f4f700a5458e09aaa0502cbd60e48ec9b832274e262bb1112299ae455f00e7ee6fb1c80cdcc7dd6fe3b34648194d7fbea874d75c3ab27f9f7d086c45c57ae6dafc19164372f7a5d73bfdde04c8b99979be281618e12f5c272757c4029ace9f6404aa48653a12f95e42dcdcdca201c5efed5d428c4c366dea3af9eb095f81b6daa4521b2171585666342e9d64f6e80555da4bda8444969fc9fe02c0b7ec6aad78f0286dcb39f0b2c1a358993c7a9920213ec814496a8cd345a25ddbd41ca6e31fe9f6abca80caac322a613ad28004dfafad578c283b7ebf4066fc16f269e4a407087c1ba90a0d7c6ad53a9787b75b69eb87cd610b4cecfaa1da06194dd03503a4025a861e283fa72f70bbcc6eeb1c7018a13e4570c9e42cf6e844fbf1de486277440bf7bb2ebf956fa6f35507681645fd4bf0fbd055d7c2345b7eb495952948bd5ea12e965c190ef6dec77f838520ebe691d95f3d2ba2cc996b67e961423a3a8873ca617276090ef06152bab734986e74674a51d44deb8979cefc535f43c24482918463d8c5f64becb3f05ff01ee79664ef2569931ffb861205781ffd2ab558c3d40cfd7a93821b218ff92926f92ff1ab666d8464b97b76f724e399231cd50f95826d1c9c37ec6b919c5c994635d416979f89e263cac32253c2f823b435c5456fcae93be60e0ac11bff83613503a148c67f4faa4d69a541e907979b15b2b3286180e125299f593a7e25ef3f41d9b0abf0f36e576ea2ca352dcbf911b423686da8ffc8c7c19e9fc68eba8740a3278907bad0e8abf3b853f849bd6bc94b88ddef0f773ee7af3d057d4991a1e947ccd3cb1376e69479177ee66be454845375fc60fdd244f25797480b0fcec66ca98c98f0c6b8438d04a5488b371ea5e09b06b304a50019c7c937ccaae38530de324b765bd76a86837c6c0d69728e4c5c2b2aca45fa2046d8d93c676f37b02013c0b3adae166ce251d4588f8714af8568d9ab35d3bcde421e9477bea3eed0389332f8b45684af4ebbb441e8a672b06c78974748de20faa2ae4a18e80120c4d33a08dda7f7ed386a76152e67ed5846e089fad1e39d5050d58b8a2fe2b6a4b25a5d7fa4984916b1953292fc7c6afa6d1d5579e1c9f567d153f52abc4b9e33ed1c02c531c2b5895761a0f070988659e1eafe2103997955ef1780199f0862c503230be370aa49e45c81d70fa5eca0dcda5bf017878f6b95476f3512e3fb43b780659b977af63aff58a3378f510d63c17057709c20f5e0300679ab70fe224b2de34bda56f5c21d0d45a4460bd286440e17cec82796da2e0d8af245a35db1e29020bc7e9030891c7af357de4c32400244ba1c837a2a1a9780d8297b9705b0d64a4073b8998e0c60bce73327eb8f25534ad31ca0b2ad2fd3c650328db045fb0ec28e992935eab465391c4b9682e2ea49a152232c332a0134d7104d7b5a497a927de813fd7002596ce441f35038c4af03f5743de311f2e7737c318f964363270e28d308cf523eb26d27c593437b4442f4af2f4a59413459c01c723e7bb3e0ff6e99e2b49e961075a0424318bce841b3d734cbb01ff9a2c85465280ff5b1b9d1bb7621f32632c76ba5556b5e667111f58ef125ca0b526d483414b8621501d9122717d30d40d46bdf9a67458ad2c9d196904154302190a336d422a461594b1060dfd30810c79037741bea437e4b27eb2befb07922bfe2c6f714e75f4f7a0db9e59c3c94fe02fcc2b315d1f518621b1d2a2711b7141f720697468ed8bbb5f54552ef4d59c0421bc3b07f0a8daa2c8de0e8239a92bbdb6d6bac60a9da08ee3e495382af4bfe673f6a74ba25b86ef54b0205acbcd31d29cc5109b3a49e8648a0db21746b0479c3dc25b5765ee5ccfb3ad484bf1b21d9408410f4863f01704ae9caa83ba1a19743641c69fcb0bc8c7012202c0e86917b9758fbf1d2475da7b8c714dcc87362b1a6b0efc831af6abe6bc64ee5b908c90530c86295d548bc4e60d626ef706b3cb2fb996f14dbba2208befbd68ea9418eabbdc1d87f0dc463b48a5b2e0bcc11be8fe697321c74aef6c4afd662e16e861f9c6f5a90e5289e7af998cedbb73121ecbdf0ea3ef32ad45452481afeabb166aa0c064686450616441ea6c66f5a9cbd9ab18ebcebd219acfeecef9fd369b1742db9b0a2c9db6f2c55b59d650a387d4ec6e106d69915d733e7a32b7ca9d9850b44547af581630dfcf4711f78a967daf9b9ca22e8c4be5adbbb1da4cacab3061f928207e6de93f6a675c272163868101dd80c83cdec0d8166190ec08bf4c38c5c05eec84fc6c8abb02dd672aa901f87430a4b329f280f61b431cf4357c010b4ad3e308b36bb4dd92e8abd27eed8688ced05327ac42f27e6bd448645b0ad5a9d0afe597e87504fe78648df10671d89617b422bc5492faa73876c4e8a8861c3d4e69a13de32a214c1a89fecae026225e62004ae3dd937e27fd557ce68a84c1575b0910cddf28a92932414cd9fb1dd29ea2bce3444a6d0a98152b1991f028236784c5bc937ebafd7decda605c4e372933ab6975a0db312d791f231fb6aba5564468933e16cfcab5433fdb4a9baa2e0805be97ce09b452b29f7d1aa03c2c79a8dd8796e356b18c598cbb0f943c62ebb9c39ecf9f99c013301621d55079f7a6cabd8bb2937c535d6aa802a16d6451ce1aed115550781ebaff01738800739c2877e63e8c499128d8e15d5b4b3291f48e8507cfcdc7ec76e095be149f27fb1dacaaa2ca09b4161bdd1217cba428884b885356befdd8371ca9df05eb394b2be93f24135b23603f42106865202175e34bdade14c14725426189eee00bc3f070ced7b07bca5c263f4f3c1ba69cf45092c236afe9bab54e2b09d9dcde437233665ff4af14b871c0ead96d34a315832f4d3d1decc48e89d47168c86d68565645cad3b3ed6ca4a95b19d1acb678ed2ea8cdda36100dd6e57a76ee53bdc65bde1fca8a0b21ef66d0f36f0a4dc3b9c9350178fc8614442cc63aee58f5fe23c83fdbf4393f65a34494439577034d5eee6b76d2ebabcd0d4a846cb9a6c884d7789872a1c653edb82fa814f6fdf7436ad835d04771f579f6261bfff6f3ff23e3054f63f54582c43f49be2142b6aa99962f87b342d4c771874e924b92c175167016de0a67d3807ec298b44e9c9fff071b0fefc1fd449b38b999e1b711c6dc8a1a85eba594b03550ce89db6d2918ae2fa5e5ef87bb2432201aac1b2548b8556cfec7061d7f37b38ceecbc87dfbd819a725c7908f89b5b1dabdc65a460d418d0eb7895c99994d71c85c41ea9db57088586093501a41baa9fd40df3278c2df3f1c1f788e5a821054cc577df114777934c5fccc18b5d9299e32596478e1f8b5742fcab870ace51cf3601767388fc998a45d0006f9c010e1ffbb1bbf192866fe6da787d9de9e16b202835ee3067b8a5710a6f9f1e5e374924697189eede8f05d5a41d526473d084bdb0a13d012ab5fe258f1d2eef68a51fd813588c8fd5b6608c6c541077e6ad137c6c1eaa93c93d3b326a44f4995f4e1cad48a8d386369ee16f3ad7c1d49609a504fb2ba49efca355cc8c53a0a448972c6419c1d696fdaf237264bd06069c2f613e45f867af01ad781adde5ca2d566019f08fd2fe9ada26c35f3095c1384709062e240bafd9d5711a2478bbb39af17366d5082dd300b92ac6581820e0cb183d2b4eaca538831ea3778681b519ec4ec96c1f20d34eff13ecb71d8a1a7184904f866bb2dc814c80c455de5f2e5017b1e38b28c9d26f49f175e158a7de318561e5fa97f6ba9eb29ffc521b94466ab4b4c00b6275b19965974867f1380787b345f23652a2a06b1cb0c4b36547d60700d915cdaff7a5dae4ccc5902c8dce37d9be2e8eed228d5bd64212a516bb35c39e9f69e52e22f2b9e6913c53d35f11eca8b84557539e631154b6a71ec4eab16babc158af1caaa742523754884ef69c62a3e53a3db0f551d4767db571fe0a8ad6ede1ae3396b40cdc19ab01117d44ef5da09963183db0151024e235aa97f644b99435b61f7c60d4c50d4f9fc48e3bac8bd57028744e377b829c44cf77451808589d3d6b19a09511d1bceee9d0cd094d2bb181b5148b23c456dde5e54e97daa5cdcd8c33973d51b7f2c08a5a6f26b58cc7bdc21108059f04497149a28cca5740e3eeb72306ce4344c86e2fc50843655972ce54a3c6a2c1fed2ac23d36666e9a8369b51d206636615c6a539cae30e7d0fcbf6275bbdfd9d509bb7914f2728a8c0ce039161b08bd7010a539cbafad0a97d0847e24a3e05cc2daf50c0acf4409376859bc201b9397a7d5ed07f4059dd1607a564bc0ec54ece5b5c1680a846616e0c058b192cd8780092107df2d47b84c161b79845d1bc6ca1043ad6977a1dca3264a54b8e4db17047de9bfa2cf77717ffe1549230c2afa1684dc2a3bc7590b098e7a896c57e0caa172cb1174e51bc8d77d831051fdfc01a7026d8904599fe87659c6781ca120e011bebd6e111bacb09743c37c0bb20545df91c6ca2ecee2112a4eae506a35754f7d0d302222c2a70c665f3ec001aab8c375cbc11f0b5f095e75e3ad5d2d18eb3827a44de165e92ff980cc2a1043b1049cffd185a49131b7d6e58c90eed17b4a4a82000e7bb5d79269fa6097b37a854d9a097f2e3c83238ff4efd0e46d46accf0ade825b8b60702a068f1302e6e4115abf25254998830cffd6a6119412dce6c6f7c6f9f28a01999c4afbe2cd4fda127cd883303ad954af1275de70fa7beacebcbb4b2c6fb98db13996ce62f1c391d222241555ab9856d2bc8cd5813b7ff8da47a4bfa4d935d22399713fa76cd827f0844a8912a230146236ca61578b692f11c5def686fd96364f8a69a98d8116a92303a961a1e025a7e39a7d2a210168359c751771333b3a539a24c45724a33f64460dd32503de82e709aec0b9d98d5e730e1126179349f9820e09cbac110a9864678311c7a5f043e1f54bb2202d59b6cdb7f9622d9bd9b5778a48b3f1d42207e762d2afdd107a20ba985d6fd6f9955bfb9df3884c1c305d4ee2fa9fa90aab2c23019b631350561456ef70659af1ca1853f91619993f8a00429485bb7ce0a77c816a6e770ea07aeccecf5a8785020311749212cd00223b62512280205294429276cc70926a8564b09fc962fbaf993aeafc61d386b0693041088f2ada92940e4f8e51794875859ef60007d700ecbe9008b39ccf670a563c844d88d1468b9ce1258a76d4ba80ae2ba12dc2bddee2c0bce309f025d7735230da73769837ab031cd6949ff5396a59fd9d76c5afdb708d31d4c29a19c4111f963502d8b1db0db6debe8bb635cd924c1e2c269398f110d77a5bcabdfac88873a1c33cd1747429c3798bfd1548d2e38bd189a9d33e4b65280733e011d9437ea28953379c7433d8d383412cfcfbe838b8d10ef2697c84c6695dfba005b0b4d36f8a3f627566551b02c27e2549c253110ff7cdfcd643e2379f61073e75b1d948e8ccb831014f5c525af48ad6643b25640497efe02fafc996a5db4d02ea8cc1baf565c976f049f77f88fad8864b196792fe58174eab7ece45f00a6e7ab13fe58b9f023a58623def2a24a5ccebd6f6205da136d53ae9263bfd558f64ff0f002c94f252a4bcab6bf514f5d87e63fe69aaa6609894d77a1b2dd6c8ba30fd360f0fbb6fdc8d86ad91582b726675d92ba54d5fc422d3f4cd85a53bf78ca9d8790d2fd0f1e9bfabbd9bb8a6e484564344d3d4f49caa2b69cd3593f2465cbd475a16c8d37a3066fad9453af1687e0090457eae90b3ece7faadb8b9b681ec5b65587532f2164b1b5befc5b46224f1a670c6f7f2d2e2bdba6141305bb2b7a607f9d8f2ef72d622cc766c093560e51e87cdb7a937c8904e1ae093e7fda741038d0537386ae8426bf16045a38f1e2eb905b05f3adad3fc82bf54839bd7b9630179582c4c51d2a8fa58191a6755844588a5d004d1c1b6255a8b91f7a03c3d528b621f67b332486cb2b89f09dababff6dbc7eaf079058cb7fd507bd49b76fc77ab3372d7589e3eb25f4730ae52428c0d9c12ac399e2836d59c84b757df3aafb1f50e4021120bf64c13eb304e89a9eef31665faefc6ae952c5b808465cb5847b9731c4cd789a86bddcdca5d6120013a335ee57a8c848a8b94d6520f35a61a211ce37f26d954ab6a90f5ce78e1f9fc59f059d5494140b03159ab1d213bc6a7d6df9326e38ac9ed6481afafb49a8e77be93cdf1944b8a6e27d9a094a5bea3227284dcb82758db0b7be7cff7a1e609f9d2d7e99920c855593ce73b05c9a1753793699c351f01c5d502c19d0287546c774736950922280986844a8c9c7b80a1e34093ce16da0c87667c1384a622063f3804e09c62f18cbc9487e0963dfd856fbd30097bfb695db1ad04f53ee765869c7925adb42a8066940e0f1bd0dc70e09f5539eb3a9aa885f8e73dd505a8ec1599f66025bc1cbf8359d16d96595bdf93b003da12faa6d0bad0ed0e4e86e2168cd212357348ede4e29e7be72d4b9c05d789f17b4ff383cb68671da6c323603ccf16b7b68c22aa9ac49c60f7062e40a81ce12e92a1b805bcbb225a99654ee54308e3c7de3f95a0f583ddc6772f20258d56e0631371be878e0f7895f677d1b730581aaadedd71658ecac4648932a8098c5093c84adf28a25db83255350ca821e5f52d083abbf9c2badc3aa80c6498a6c1a1083fc788cccf123f802e08ad87d4eb9bcceb4006c093823e87d950734af8b96fbf62045a6c557844e8cc48a31b7a27f1a87982538ddd5499d002e35e2c8298957c588d757ab5a9228726e7ded98466d439a55b6e51c614eefc16878c19c9d3b6c6b8069c19ad7c1798118cc49f33c2e20986f57e5dfe626ba08f8c2692bc3a6f745d3306804120c7f2c31a5970d9242f2ef0df07b97df3fd21188140909aafc6abe8eaaaa20fb85ebf60a12e4b97d77723fc756c94601e47c0594e866bb89c766caf2d26fdc0e4bd583040ea64f76025929aab4e6e6fc52c8aea37d29d88babbed8874a1f77f8fa4b80f67bc9bc8117f06e7c4a9415039d40f97eb4a1aaa4660fde0fe898b15f5488eba4f703484f2853f91ba314170b3ef4eb609dcbd7706be4d69a23b44a9fcc66155388f9ad463401a6984d337e7cd3a3ce1dd67ab91b205630c07b2c8967e291ec07b3137d1ca493daeec28de3a188e930c645eb22bcb91a2bb6ef6546ba257b88e92cd7d507acce6fcc2e5eb42755a3edb930c26271e4416e17a619be680863700860c8e93f47c035a90ac134b645744df0e04f8724876822979568109e6ff2692d56cfff74cbf7ba43296196b4cae1f2ce3652cf6d86e9e2c29266d0b1d2241eff62d4b5eb684c521bc5a81bc5869764958d3c17e7b36d73dc610d190d12835baff8b1774550c7660f153701ad7ac39140ca923cbb33aaac15d4c56699c7fcbfff96a01f2c1951857d0245c2d202c758d29e7452fdbf0f4ce29ba1610b94f6fc781b66d13bdaa08dda551a07972e84fe64296a069887ad13315900bc034b1c3d2748ac8166bc87b421a22eb2b213ae05e8f4449fab2699a149d64b7e88c5123615baf6f5479a700e4ec9e7f0605ef2927b252f13a5872082c09ef3534f7faed1f05910f60ffb23b4aafab763557680279dbbdb39da01952e766daca892fe6134b78aaa2b85ad50b3a6b26323a696f88ec478545e68b01886cf7a5fdd6254bd78c579d421c73274da92626e0cbcf857cf5d8f2bbd171b7ec000efa955f02821f6d6d9a32c4750472038a377051782abeabb84bf680a2d3b53fc0e356640a0735a25cb1894350fe7e9b6b399f2dbf352a1c51dd45e4f85053f5b534973262829e9f324082693c960ab0f9d73ff23db68efb09396e8cac04fa90e0e3d1591f9233c882922bafa0e310f2cf717b33b9d954d9fa972a06b9c04cf5515faed843066cbb3316f725cce7468c9d475a2cccb26eb6867787817fefd878c3710e5e65211168f69f2a293fdbb72d59b33fdebc4fe2130073cbb1505eba12a52e466414ab6dfc886fb7eb3fd70603f077a9cc2e1b7ace14eadf011e6373d22eb2748f71f1f7aa83935c4c82fcb85b317d077d251a9c1eec08837109417c9e6609f5fe80b752e8adba3635e4a5b2fdebd8dac1c07d081c0b73c98397f3f961af4968d0702dc7aba230f2da6863fa4e662e5cedc8148a9d69e7ad07da558d6ee905356219a9367fb970596017329014653311b3dd08789736c4c8482ea3c783ba70b7b3aac3675b5ec70d61878073ebceb530b3f377431184dc79035e6c030ca86f8af1a754df4f8ce6f085ebcfabb035f1f78f3b917901c1a3148fa4c0160512994b29c06bdccd6322a22a45f7e5fe5a4d8f5c68de0fee7973194708b9dbc95bc5a4c826ecab8dcfd61ed391e6fae0348564fd6404b6e732834db2589ed9cb2cfbe3e97c2241e684e8051e998c3afe3a7e60a373c87dcc905f4bd1160a7266067aa058367643cc66dc37213d94c7efb264ab98aae9eee92efc4812261d4383481b293143bec7edf57f22ff7ab0b63975c27212eca0cc41babf8da97bfd78a83c2d2298a398a3742cfe85d3fbe225c2c24e34145d47c8488a6917de1385c8e2529a91b7d2b93b702dca61b946dca955fbd0fc2d05167e93f79e8e19134559881bdb8eff0f9570ef5232cef7bd20992d2038da12fb483f1d54912737e7d51b83da88bc2655a710aacd2cd78fa46e6c997b0b5984f103b72de334646ec751a011d7b264308028252f9dcf728cc3c06b9d9ca8e3bc1a1ff54a3064f1b344446c7575d1276a8bc9db9ffbca4a2ea8e5b1e61f67af346dce56c9b37ea706a6ff32a19b9b4067e5e655168b7a73976613630e877e5dc03d25e3be92ad1b0cd813c1df124d39641d0858eb99b6a756fd1f207ace0648433edc47261b5b222dbb218a13f1456e875888dd2b61284d3d5561ca36eb65c609f52e17b126f85986216962f1625829d18d94d389639e107e39aaba878f07400d73dc63177c4d9627dd26ddcc801161274ef21e965453d09207e700513e79ebae00c384ccc0ca81bbd78880d22f491f9d4dc1c0877145427fa1e04a7bdfa8402b9030837e8fd2666bffb99a205fb2e365a1d27cab81dc396b7b116f159e3ef7cf6cfe92f7b223c0c1217d867de5e9a34bbaf4b8c7d6b1dc737dc75276f83e608a18aac5088b9b2f437741f0d50629dd2120407d92d1f4d263c5454b152e8806c53875e956529c8d13a50eb99a16de7b2e80dbf2dbcdb065d42010354bf57f03d7df22ce95c279cac35e6ca7b18a8296a4841ba07b734ee8463d4e78e6acfd48457d24e1527f6105199cf1eac36454842315befa348d24966fb6b2942b9b6fa28e026c0d66cc806294429d3163b9ee26128f4c4e7e49e5b233114a7eb8e6c3a6d45d3780d9111e8ac0f30708036eae99e8fd69f915b4d9d48225fe4336080394c5f726dcf9f2eace37b55b5d43412e1826eb6e295ec8da5062199de904ecd2fdf8a4d15924b2160bfadc5b303722965691cf99d5cccbd8c29f010a9838a64c09d5bce90bc08f486812e638001223a448921a689afa6d81b7fbfdd922d3c285e9182abcfbe305c037e21102a8731aa05d8c1cd4db39155f5d1335d02b15422e0ef328776006129fc0483e79a310e3efb2500060a361e204033d48be6249b66739142a82e03ee06f5b16c829e647bc29bfc9b661225820d2cb849319b6d0448f7609ec723e611e8d1f03da1448538fa2ab9344992d4bca82ad71325d3575996f8fc7d91c191028fe1f6f246ad41b63abc65fa1e52d6417ee71c0e5da26ac61c82a57e7e4cc26fd3deb1491eaa248a49479977b353142c39ee018f1262137d37d1f38edfc9a2e635d5153699d976e5aa986db9a65204e5346482275ec21dfb482e836c6cfe8d494e64dd13561479c7ed46f27eae0d80366c836cc11f0cbf8f197db5bb07245263249ed530d4642d1e241f231b795ffbb7b18d28e4962f77163a10cbef7db92a19a0fa866e81ea53a3d36f21242d05c5f1c0bb4279d3521f902806665a04357990cf1d72460ae0ca2e273467ed5f8333717d321b3ddd92f0b2d31f5744b5d49810d8c4ba6c47a51d7d24e30e631b8e20002b040a1de5075023ae897daafb4285146f33688e4792a79fcb36824c1a98091c7692b1e023c548c40afd8d0586fed448f2e7da560c6902c85935c5449ed2e101610d34ffdc6076fc74f87ca3a76d1b667ec38c9cdb33c486f8579e4fb861f1d3bfdcd7c4ff114572a4f18fba187ed4b030a513f9ed252ba1b6a9d4bb1c5bd70e9e6dbdf516ccad5c69d4b9cc28b8059ffbe0ac48adf1340b4a414fb897f51a3d9c57299da011f6a57aa58995c6de5814c70e6caf7a3249bc1ac29b4b9ca99c6656fa35d7846a34ea40796f8c1f05c5d20f05d57e1deabeb5a84537694213b934476293fa694922f684f66617e9c97628fe9efc0c7295907744b67140fccc1690405fd3d6b185566652e1e18c685088cfa016cb194c2c86ec2e39d7825c977f68b46096c238734226e30fb014f774660c5f1c0116faccdd19aa4f3906d734450a5f31f0ae22ffe49534bd20a09eabacd7a49f0e738c333555dc0877cbb778b840a038d281a597bb6ff79d033843c0c8df0de3c0454862ee428303a80eab6571ab61a66a19bec2d8a8ff5d573f468ea26cacb3c96745c4678c795d742b98533bc61d8c930a100cb9a757d62c554f8fa7bde7d019fddab57bf2d6ac7cbbb5b85d5471e39314c3faa59e5df2400658394df152a8f779ebcd0dc489e5eb85fb4fb41806a4e40c14b226236f0e419880ccdf739b5fad7958c35beb243aa33713eab7a8ce29f3b2130cd7460a6ddaa62cc4abdd8df7c04465396482f9d84c8bc0dffba4eca9f7b10f043194566cad0408033ad53b704752964bc354877cc7c494f2714103a2d6fe12ab20a5ac6042168cbef3d0448c12fad8366d09b03830bbd359d01139b8e515660217d82692f5be30999cf60e2e7e3c78f00fed47de7994a6b45c9843c7da8ed08998f392e48b72270ba7375b61babab937410848b3afa70f9e7c5bd68a0902e12a4ae9617f933ec03270e7560cfd333a4fc525d17122913e7d24985a9becd1cfa864477eb5ac2e061616b52f89b4e8e893449ff951ee102ff45e266d5c0a1225b5c0e57ac95e557e6a67f331ef68012323b0fb73a6779f715b69d41dff6fde128fe71676eea5999c97da5e6e0c0ed4cbb3d3fe70e3e8ea2d03f59e64fa9d45c81bd11b99ff33e62503935e50f6c04477f45e00c014454ef64dd49bb92fc20084766988adbc9b35142dfab262f456f0d9e3dfac8b6d4106ee5b1513f9cc215343cefa7854ff68db1da31db4d2f80caf1e52e4e14338137dfe9667852a3eca6f42dfe381796fad39d932adfa6b847199eb56dd04cae2697a7ba7754f35c37317f81d62f3eb7f5a764874efaf1c9a700d5261eb8c109921b453398f459ae6482be8cf6d9705a8263d4c67767e88997d078c15a246bf59b4d53d407e16950366d8f126ec5cdaedf514789364364b4485ed7a325d7c8fb964eaa9b140e797e773c608e7994c066b889832590c6ff7469bd154c3535ca326009aa23f1c9d19f947b978b2b08e3059db117d7d20da5394b549e0931d29af53070f8b40f0cc5cad338e4026687e73e87f452f1e51db39bf3334e1ea69496c9688609fb22c0e51619c80bd8c5cd573f636243b25941ecfa17063e8ca1a21fec58aeff87fc1bc3a92ee72d9501f300172e683d6e04b38b7e89de1ff5e801d0d881c314a75a014754a9d2354551e4b24b6b2d6b486ed49026b9df0e82cb1aefb84866fa849911c61c599365ddaf73c8679ea4d9d22285fd72634f5dc700978d7fdb61befe301012dca2dd103d6752807cc204a6101d110b6a5ecd5aefa8af2b1fed1ecf15b18e686d202daef48825213e302269ba386a17049b5c4fab54de595a5e2328f27088d9f56c6bc129ffbac88aa5638e5449f361abd1d2d91f2f65ad1ad385b6d5cf3e3d9fddbe1cc5dcba2583601a81ac376bf07a5a10be0c27c0424cc38c04c2f253dd9fd01a205ff68aa49c0725e129eb3d9ba390b25afe3cac92a38c050a205549a0aee293850081ca71d3f4b86c72a282072a7e454c66a1304be0123e6cbbdc3d855bd433379d194ececebf86163d37f31ee15e5edee526cb7cd1cf96c863a20b2f90b4b58e02210998026c88e8e1acfea900518a8138034c6fe0d39a54ddedb04a3c66748bbf6785cb74b3e8d3518f8079d005cf3ae15cdac1abaf93d5827589d089cd7daccd2da464ed3f87d4b0cf32cbf298aa6b09c660068b6b3b588bc7f0f33f918bfdd33c75353b623c26476c4e9ea9b5400bca8a17a6b5ccfae433f63095e2c0792d601487c47c035999067135d61b0f1946db4b851aa2f7d586c19e838c2cd38e10f575d0b49a215482ec6ce25fddfbb00f616296846007d5271520fa7f1ac003efd7b1a0bd7eb7a7bfa7ccef8b402369d22165e07c9476fdf2aea66c34e8c92a6ccbda6719ec368893bfcca150c6829513eaabdbe7bf2f37245e3b160e7ce7ecfd654d3360a77931d50c63daea7579b4a0c92fa1a6a9c971f27e5e6e2e19a077227f6bf69aa6bd7556dcdcc088646468b4ab2db6437a66e045b15393a50b73f9a76b9816142fa10f324f488cd6215b7967a49f097abf6955e22732cfd3ec4473e73557f56de4db376b9af48ca9f83135ee7220eba45c377b01ad135811b8ed810c0a3fcaf10469a265ef4f3f737270b9a80f617f2458bf38523575c9022668c3760df9d88e5c05367b6ba0079ef9cece2f61b8d0eb23cd40670975e74b4c5a3607f2c4410fe0bd59b6b01e3c7f2ef03437672093b43bdbc8fc82be83544af3c7d53150ab1b3ebccc9219e8e72decde672e233e80030dd2c69e9abaa0b0db9baed49218c7a6940ec6fc4a887c22c3a5141362a7b6f615c15d60fc558c997603085895617e6ce71a57d34a30485907d27703eae64991262fbcbfc8cf78219b6fca49f1671edb0215c1b75b1e266137bd6a142ade281a0895099d58803e0a450cb8e2a171613f63e3c417cd166e2cc0de70e152af55743dc12b5f1c69a740ef28f7ec06562495fd3cce4b2ededb368492f6e2509417f4f0cb09dd4f57e0c33e7816387ad6b47922361f6d86210fe516a048738db895c0a2957031883704df1346ac31b626e0f0221f602a98f126f8962513e54bb2a5494c98b220f30f564980fac36dbd33ce7b5090201b106d169e86ec8f0fc189f85ecd5beb5b2a3282dec14e52aa4e2f0a08c651ad6bfcfee47eef72d139c72184d7715c49b3dbbbaba3a7f55546da5bdf45704d132d9cf3524906c9943d66a0c0289863821fe4dcf1fb001f44ca95b005039d2467d49ccce0ff947c3ad9497edbc36aa227ad9e1389f5b9b2df87dcb1bb6029d6141559218323ef7f99f86ee9e937654cfa20e829ac33ebb44fdaae313b4fdb85f2e4e0780a52f6cb9b4b709d5b70eddd93d45109e11e579bd4b2d8ca82bc3b4b3e1909088d9d15d598dde6d44b107f8711e16bc04beeefaa3aeeb815af7f594461e0946337cdcf0b14feb35ef42aef3455b057ec56fc04aaa30ed1cb6d53ba35e3eaf0df4046eeffa3fab285ea31598e7309ddddcc587ed4ebcf37b2e317b0e1785a53f616d767152ef313146704c80990e3ce9f91bded474695cc227c8174f5f5a1dc8129ee37759756d54a3f09e9e642e56bfbc800effa2643b99f265c9d0ec39c0e4b54a9c34ad71686a082e371bdfa3fb286f91113b22d99d7c4acef7c7da5b8d1e0f9c4c553ec798132b98894f33eba0cd30b40374e686a521e8a566148e5425f72f7750fa108aa12741a1b04fdcfb1df6b027f45c4f1cd8d1b695509b907280e49e96b8afdc71cdc576a51a9944429c10a9026cc52e45e0ad4";
//		//使用aes加密
//		String encrypted = AESTool.encrypt(xml, key);
//		System.out.println("encrypted: \n" + encrypted);
//		System.out.println("encrypted length: \n" + encrypted.length());
//		
//		//解密
//		String decrypted = AESTool.decrypt(encrypted, key);
//		System.out.println("decrypted: \n" + decrypted);
//		System.out.println("decrypted length: \n" + decrypted.length());
//		
//		
//		boolean isSuccessful = StringUtils.equals(decrypted, xml);
//		System.out.println(isSuccessful);
		System.out.println(AESTool.decrypt(str, "adjdjfjfjfjdkdkd"));
	}
}